namespace DotNetNuke.Services.Scheduling
{
    using DotNetNuke.Common.Utilities;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Text;

    public class ScheduleHistoryItem : ScheduleItem
    {
        private DateTime _EndDate;
        private StringBuilder _LogNotes;
        private int _ScheduleHistoryID;
        private string _Server;
        private DateTime _StartDate;
        private bool _Succeeded;

        public ScheduleHistoryItem()
        {
            this._ScheduleHistoryID = Null.NullInteger;
            this._StartDate = Null.NullDate;
            this._EndDate = Null.NullDate;
            this._Succeeded = Null.NullBoolean;
            this._LogNotes = new StringBuilder();
            this._Server = Null.NullString;
        }

        public ScheduleHistoryItem(ScheduleItem objScheduleItem)
        {
            this.AttachToEvent = objScheduleItem.AttachToEvent;
            this.CatchUpEnabled = objScheduleItem.CatchUpEnabled;
            this.Enabled = objScheduleItem.Enabled;
            this.NextStart = objScheduleItem.NextStart;
            this.ObjectDependencies = objScheduleItem.ObjectDependencies;
            this.ProcessGroup = objScheduleItem.ProcessGroup;
            this.RetainHistoryNum = objScheduleItem.RetainHistoryNum;
            this.RetryTimeLapse = objScheduleItem.RetryTimeLapse;
            this.RetryTimeLapseMeasurement = objScheduleItem.RetryTimeLapseMeasurement;
            this.ScheduleID = objScheduleItem.ScheduleID;
            this.ScheduleSource = objScheduleItem.ScheduleSource;
            this.ThreadID = objScheduleItem.ThreadID;
            this.TimeLapse = objScheduleItem.TimeLapse;
            this.TimeLapseMeasurement = objScheduleItem.TimeLapseMeasurement;
            this.TypeFullName = objScheduleItem.TypeFullName;
            this._ScheduleHistoryID = Null.NullInteger;
            this._StartDate = Null.NullDate;
            this._EndDate = Null.NullDate;
            this._Succeeded = Null.NullBoolean;
            this._LogNotes = new StringBuilder();
            this._Server = Null.NullString;
        }

        public void AddLogNote(string Notes)
        {
            this._LogNotes.Append(Notes + "\r\n");
        }

        public double ElapsedTime
        {
            get
            {
                double ElapsedTime;
                try
                {
                    if ((DateTime.Compare(this._EndDate, Null.NullDate) == 0) & (DateTime.Compare(this._StartDate, Null.NullDate) != 0))
                    {
                        return DateAndTime.Now.Subtract(this._StartDate).TotalSeconds;
                    }
                    if (DateTime.Compare(this._StartDate, Null.NullDate) != 0)
                    {
                        return this._EndDate.Subtract(this._StartDate).TotalSeconds;
                    }
                    return 0.0;
                }
                catch (Exception exception1)
                {
                    
                    ElapsedTime = 0.0;
                    
                }
                return ElapsedTime;
            }
        }

        public DateTime EndDate
        {
            get
            {
                return this._EndDate;
            }
            set
            {
                this._EndDate = value;
            }
        }

        public string LogNotes
        {
            get
            {
                return this._LogNotes.ToString();
            }
            set
            {
                this._LogNotes = new StringBuilder(value);
            }
        }

        public bool Overdue
        {
            get
            {
                return ((DateTime.Compare(this.NextStart, DateAndTime.Now) < 0) & (DateTime.Compare(this.EndDate, Null.NullDate) == 0));
            }
        }

        public double OverdueBy
        {
            get
            {
                double OverdueBy;
                try
                {
                    if ((DateTime.Compare(this.NextStart, DateAndTime.Now) <= 0) & (DateTime.Compare(this.EndDate, Null.NullDate) == 0))
                    {
                        return DateAndTime.Now.Subtract(this.NextStart).TotalSeconds;
                    }
                    OverdueBy = 0.0;
                }
                catch (Exception exception1)
                {
                    
                    OverdueBy = 0.0;
                    
                }
                return OverdueBy;
            }
        }

        public double RemainingTime
        {
            get
            {
                double RemainingTime;
                try
                {
                    if ((DateTime.Compare(this.NextStart, DateAndTime.Now) > 0) & (DateTime.Compare(this.EndDate, Null.NullDate) == 0))
                    {
                        return this.NextStart.Subtract(DateAndTime.Now).TotalSeconds;
                    }
                    RemainingTime = 0.0;
                }
                catch (Exception exception1)
                {
                    
                    RemainingTime = 0.0;
                    
                }
                return RemainingTime;
            }
        }

        public int ScheduleHistoryID
        {
            get
            {
                return this._ScheduleHistoryID;
            }
            set
            {
                this._ScheduleHistoryID = value;
            }
        }

        public string Server
        {
            get
            {
                return this._Server;
            }
            set
            {
                this._Server = value;
            }
        }

        public DateTime StartDate
        {
            get
            {
                return this._StartDate;
            }
            set
            {
                this._StartDate = value;
            }
        }

        public bool Succeeded
        {
            get
            {
                return this._Succeeded;
            }
            set
            {
                this._Succeeded = value;
            }
        }
    }
}

